import math
import time
import unittest

from DrissionPage.action_chains import ActionChains

from autoTask.core import taskMapping
from autoTask.taobao.ztc.gjc.OptiBid import WebOperation, TbType
from autoTask.taobao.ztc.gjc.OptiBid.WebOperation import AM
from autoTask.taobao.ztc.gjc.OptiBid.pojo import FilterRule, TaskParam
from common.utils.web_page_util import Tap, MockTap, Input, get_first_visible_ele
from .Main import Main
from common.utils import web_page_util


class MyTestCase(unittest.TestCase):

    def setUp(self):
        self.p = web_page_util.create_page(is_refresh=False)
        self.task_snapshot = {
            "taskId": "2",
            "taskName": "阿明-直通车-优化",
            'isTestExecute': True,
            "param": {
                "markTemplateList": [
                    {
                        "filterList": [
                            {
                                "field": "点击量",
                                "comparator": "大于",
                                "value": "30"
                            },
                            {
                                "field": "总ROI",
                                "comparator": "大于等于",
                                "value": "3.5"
                            },
                            {
                                "field": "总ROI",
                                "comparator": "小于",
                                "value": "5"
                            },
                            {
                                "field": "总收藏加购成本",
                                "comparator": "小于",
                                "value": "10"
                            }
                        ],
                        "cycleAdjustPercentage": [
                            1,
                            2,
                            3,
                            4
                        ]
                    },
                    {
                        "filterList": [
                            {
                                "field": "点击量",
                                "comparator": "大于",
                                "value": "30"
                            },
                            {
                                "field": "总ROI",
                                "comparator": "大于等于",
                                "value": "2"
                            },
                            {
                                "field": "总ROI",
                                "comparator": "小于等于",
                                "value": "3.5"
                            }
                        ],
                        "cycleAdjustPercentage": [
                            -2,
                            -3,
                            -4,
                            -5
                        ]
                    }
                ],
                "bAccount": "赫巴兹旗舰店:开发",
                "bPassword": "hbz18374844582",
                "bidScope": [
                    0.05,
                    99.9
                ],
                "premiumScope": [
                    5,
                    300
                ],
                "isUpdateGjc": True,
                "isUpdateRq": True
            }
        }

    def test_master(self):
        Main(task_param_list=[
            TaskParam(cycle_adjust_percentage=(1, 2, 3, 4),
                      filter_rule_list=[
                          FilterRule("点击量", "大于", '30'),
                          FilterRule("总ROI", "大于等于", '3'),
                          FilterRule("总ROI", "小于", '5'),
                      ]),
            TaskParam(cycle_adjust_percentage=(-1, -2, -3, -4),
                      filter_rule_list=[
                          FilterRule("点击量", "大于", '30'),
                          FilterRule("总ROI", "小于等于", '3'),
                      ])
        ], is_test_execute=True).call_v2(self.p)

    def test_api_master(self):
        taskMapping.ztc_gjc_opti_bid(self.task_snapshot)

    def test_init_filter_template(self):
        AM.init_filter_template(self.p, 2, filter_rule_list=[
            FilterRule("点击量", "大于", '30'),
            FilterRule("总ROI", "大于等于", '2'),
            FilterRule("总ROI", "小于等于", '3.5'),
        ])

    def test_temp(self):
        print(self.p("@@class=el-select-dropdown el-popper@@x-placement:start", timeout=0))


if __name__ == '__main__':
    unittest.main()
